var changeShiftsInspectionFees = function (targetObj) {
	this.targetObj = targetObj;
	this.sysUtils = new kendoUtils();
	this.totalMoney = 0;
	this.init();
	this.dateFormat = "yyyy-MM-dd HH:mm:ss";
	return this;
};

changeShiftsInspectionFees.prototype = {
		init : function () {
			var fieldArray = this.sysUtils.getBindFieldArray(this.targetObj.find('.search-panel'));
			var functionArray = [{fName : 'search_btn' , fs : this.findReport}];
			this.models = new bindBaseModel(null, fieldArray, functionArray, null);
			this.sysUtils.bindDoucment(this.models, this.targetObj, this);
			//默认查最近一个月的数据
			this.sysUtils.mvvmModel.set("handoverTime","08:00:00");
			//核对查询时间段内的差异
			this.inspectionFees();
		},
		findReport:function(e){
			var that = $(e.target).data("that");
			that.inspectionFees();
		},
		/**
		 * 核查指定时间内，交接班数据和车场数据不匹配的地方
		 */
		inspectionFees:function(){
			var params = this.sysUtils.getBindDocJson(this.models.bindFieldArray);
			params["handoverTime"] = kendo.toString(params["handoverTime"],"HH:mm:ss");
			//父级页面的查询参数
			var paramsParnt = changeShifts.sysUtils.getBindDocJson(changeShifts.models.bindFieldArray);
			paramsParnt = changeShifts.getQueryParams(paramsParnt);
			params["beginTime"] =  paramsParnt["beginTime"].substring(0,10) + " " + params["handoverTime"];
			params["endTime"] 	=  paramsParnt["endTime"].substring(0,10) + " " + params["handoverTime"];
			//给html展示界面写值
			this.targetObj.find("#feesTitleDiv").html("核对车场收费统计报表时间：" + params["beginTime"] + " ~ " +  params["endTime"]);
			if(isEmpty(changeShifts.currTableList)){
				notification({title : '提示', message : '没有数据需要核查比对！！'}, 'info');
				return;
			}
			params["shiftsList"] = changeShifts.currTableList;
			var that = this;
			//后台获取差异并展示到前端
			JsonpAjax(baseApiPath + 'report/inspectionFees', JSON.stringify(params), 'json', function(res) {
				//填充前端
				var differenContent = that.targetObj.find("#differenContent");
				differenContent.empty();
				that.totalMoney = 0;
				var differenTemp    = that.targetObj.find("#tempDiv").find("#differenTemp");
				var newTemp = null;
				var diffDetail = null;
				for(var i = 0;i<res.length;i++){
					//第一个上班时间差
					newTemp = differenTemp.clone();
					newTemp.find("td[name='diffTime']").html("首个上班时间差："+res[i]["firstBeginTime"] +" ~ " + res[i]["firstEndTime"]);
					that.fillDisplayContent(newTemp, differenTemp, res[i], differenContent,"firstResult","fristdiffType");
					//最后一个下班时间差
					newTemp = differenTemp.clone();
					newTemp.find("td[name='diffTime']").html("最后下班时间差："+res[i]["lastBeginTime"] +" ~ " + res[i]["lastEndTime"]);
					that.fillDisplayContent(newTemp, differenTemp, res[i], differenContent,"lastResult","lastdiffType");
				}
				that.targetObj.find("#totalSpan").html(that.totalMoney.toFixed(2));
				if(that.totalMoney == 0){
					var notDifferen = that.targetObj.find("#tempDiv").find("#notDifferen").clone();
					differenContent.append(notDifferen);
				}
			});
		},
		fillDisplayContent:function(newTemp,differenTemp,resObject,differenContent,listField,diffTypeField){
			newTemp.find("td[name='workstationName']").html(resObject["workstationName"] + "(" + resObject["workstationCode"] + ")");
			var diffMoney = 0;
			var diffDetail = newTemp.find("table[name='diffDetail']");
			var tr = null;
			for(var j = 0;j<resObject[listField].length;j++){
				tr = $("<tr></tr>");
				tr.append("<td>"+resObject[listField][j]["VEHICLE_NO"]+"</td>");
				tr.append("<td>"+resObject[listField][j]["CHARGE_TIME"]+"</td>");
				tr.append("<td>"+resObject[listField][j]["userName"]+"</td>");
				tr.append("<td>"+resObject[listField][j]["CHARGE_MONEY"]+"</td>");
				diffDetail.append(tr);
				diffMoney += resObject[listField][j]["CHARGE_MONEY"];
			}
			if(diffMoney != 0){
				diffMoney = (resObject[diffTypeField] > 0? -diffMoney:diffMoney);
				newTemp.find("td[name='diffMoney']").html(diffMoney != 0?("差异金额：" + diffMoney + "元") : "无差异");
				differenContent.append(newTemp);
				this.totalMoney += diffMoney;
			}
		}
}